package game.core 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import game.core.races.Race;
	import game.objects.Building;
	/**
	 * ...
	 * @author Sulus Ltd.
	 */
	public class Player extends EventDispatcher
	{
		public static const STATS_CHANGED:String = "stats_changed";
		public static const CURRENT_BUILDING_CHANGED:String = "current_building_changed";
		
		public var name:String;
		public var avatar:Class;
		public var alive:Boolean = true;
		public var race:Race;
		public var stats:Object = { };
		
		private var _currentBuilding:Building;
		
		public function Player(name:String,raceClass:Class) 
		{
			this.name = name;
			race = new raceClass();
			stats = race.InitStats();
			
		}
		
		public function AddStats(statName:String,statValue:*):void
		{
			if (stats[statName] == undefined) 
				stats[statName] = statValue;
			else
				stats[statName] += statValue;
			
			dispatchEvent(new Event(STATS_CHANGED));
			
		}
		
		public function SetStats(statName:String,statValue:*):void
		{
			stats[statName] = statValue;
			dispatchEvent(new Event(STATS_CHANGED));
		}
		
		public function get currentBuilding():Building 
		{
			return _currentBuilding;
		}
		
		public function set currentBuilding(value:Building):void 
		{
			_currentBuilding = value;
			dispatchEvent(new Event(CURRENT_BUILDING_CHANGED));
		}
		
	}

}